<html>
<head><meta charset="utf-8"><title>Adding a small C lib to rustc for local use · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html">Adding a small C lib to rustc for local use</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204645749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204645749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204645749">(Jul 22 2020 at 09:27)</a>:</h4>
<p>I want to add a small C lib to rustc for local use. Specifically, I want to invoke some Valgrind client requests (magic assembly code sequences that pass information to Valgrind). These client requests are implemented as Rust macros and I really don't want to reimplement them in Rust.</p>



<a name="204645822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204645822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204645822">(Jul 22 2020 at 09:28)</a>:</h4>
<p>So I want to create a small <code>.c</code> file with a handful of functions and call those functions from Rust code.</p>



<a name="204645840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204645840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204645840">(Jul 22 2020 at 09:28)</a>:</h4>
<p>Are there special steps for this? I could probably work it out for a normal Rust program, but rustc is always its own special snowflake</p>



<a name="204652525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204652525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204652525">(Jul 22 2020 at 11:05)</a>:</h4>
<p>I think it should "just work" -- but maybe we could use inline asm for it?</p>



<a name="204652620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204652620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204652620">(Jul 22 2020 at 11:07)</a>:</h4>
<p>hm okay it looks like the sequences aren't actually documented which is a bit unfortunate but makes sense</p>



<a name="204754998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204754998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204754998">(Jul 23 2020 at 02:28)</a>:</h4>
<p>Ah, the <code>cc</code> crate is nice, that was easier than I expected</p>



<a name="204759089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204759089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204759089">(Jul 23 2020 at 04:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120989">njn</span> <a href="#narrow/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use/near/204645749">said</a>:</p>
<blockquote>
<p>These client requests are implemented as Rust macros and I really don't want to reimplement them in Rust.</p>
</blockquote>
<p>did you mean C macros? I wonder if bindgen can handle them</p>



<a name="204760028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204760028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204760028">(Jul 23 2020 at 04:36)</a>:</h4>
<p>Bindgen can't handle function like macros</p>



<a name="204760032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204760032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204760032">(Jul 23 2020 at 04:36)</a>:</h4>
<p>I'm trying to add that functionality with my c compiler but it's been like pulling teeth to get the PR reviewed</p>



<a name="204761327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204761327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204761327">(Jul 23 2020 at 05:13)</a>:</h4>
<blockquote>
<p>with my c compiler</p>
</blockquote>
<p>everyone's pet project :P</p>



<a name="204808827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204808827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204808827">(Jul 23 2020 at 15:00)</a>:</h4>
<p>src/rustllvm is an example where we build some C++ code for rustc</p>



<a name="204809016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Adding%20a%20small%20C%20lib%20to%20rustc%20for%20local%20use/near/204809016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Adding.20a.20small.20C.20lib.20to.20rustc.20for.20local.20use.html#204809016">(Jul 23 2020 at 15:01)</a>:</h4>
<p>with src/librustc_llvm</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>